import java.io.File;
import java.io.IOException;
import java.util.Scanner;

import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.core.converters.ArffSaver;


public class TrainDataSet {

	static final String destinationfile = "trainingSetNew.arff";
	
	static final String sourcefile = ToolBox.pathnames[10];
	
	public static void main(String args[]) {	
	    try {
	    	System.out.println("\nOpening file "+destinationfile);
	    	ArffLoader loader = new ArffLoader();
			loader.setFile(new File(destinationfile));
		    Instances data = loader.getDataSet();
		    Scanner input = new Scanner(System.in);

		    //Add data
		    System.out.println("Add data from "+sourcefile);
		    for (DataWindow dw : StructuredData.getAllDataFrom(sourcefile,null)) {
//		    	dw.plotDataWindow(true, true, true);
		    	System.out.println("Save to trained DataSet? yes/no [yes]");
		    	String qs = input.next();
		    	if (!qs.equalsIgnoreCase("no")) {
		    		Instance one = dw.featuresInstanceExtraction();
		    		one.setDataset(data);
		    		// The most important of the trained data (the classe attribute)
		    		// Add Last attribute (class attribute)
		    		System.out.println("Classe attribute for this data?");
		    		String cl = input.next();
		    		one.setValue(12, cl);
		    		data.add(one);
		    	}
			}

		    System.out.println("\nSaving to file "+destinationfile);
		    ArffSaver saver = new ArffSaver();
		    saver.setInstances(data);
		    saver.setFile(new File(destinationfile));
		    saver.writeBatch();
		    
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
